package com.wanbatv.wanba.jianshencao.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;

import com.wanbatv.wanba.jianshencao.util.Util;

/**
 * Created by Administrator on 2016/7/29.
 */
public class SwitchActivity extends Activity{

    private CombinationKey combinationKey=null;
    private static boolean DEBUG=false;
    private String[] mkeys;
    private String normal;
    private String debug;
    public SwitchActivity(String[] keys){
        mkeys=keys;
        combinationKey=new CombinationKey(keys);
    }
    public SwitchActivity(String[] keys, String url, String url2){
        mkeys=keys;
        combinationKey=new CombinationKey(keys);
        normal=url;
        debug=url2;
    }
    public void match(int keycode, final Context context){
        if (combinationKey.isMatch(keycode)){
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("切换模式");
            final String[] str={"正常模式","测试模式","正式支付","测试支付"};
            builder.setSingleChoiceItems(str, 1, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Toast.makeText(context,str[i], Toast.LENGTH_LONG).show();
                    SharedPreferences save = context.getSharedPreferences("save", Activity.MODE_PRIVATE);
                    SharedPreferences.Editor edit = save.edit();
                    switch (i){
                        case 0:
                            //命名debug.mode
                            edit.putBoolean("debug.mode",DEBUG);
                            edit.commit();
                            break;
                        case 1:
                            edit.putBoolean("debug.mode",DEBUG);
                            edit.commit();
                            break;
                        case 2:
                            //命名pay.mode
                            edit.putString("pay.mode","formal");
                            edit.commit();
                            break;
                        case 3:
                            edit.putString("pay.mode","test");
                            edit.commit();
                            break;
                    }
                }
            });
            builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {

                }
            });
            builder.show();
        }
    }
    public void display(int keycode, final Context context){
        if (combinationKey.isMatch(keycode)){
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("盒子信息").setMessage(Util.getDeviceId(context)).setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {

                }
            }).create();
            builder.show();
        }
    }


}
